package com.myweb.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.myweb.dao.MenuMapper;
import com.myweb.dao.TeacherMapper;
import com.myweb.dao.UserMapper;
import com.myweb.model.Menu;
import com.myweb.model.Teacher;
import com.myweb.model.User;
import com.myweb.service.UserService;
import com.myweb.util.MenuTree;
@Service
@Transactional
public class UserServiceImpl implements UserService {

	@Autowired
	private UserMapper uDao;
	
	@Autowired
	private TeacherMapper tDao;
	
	@Autowired
	private MenuMapper mDao;

	@Override
	public void add(User entity) {
		uDao.insertSelective(entity);
	}


	@Override
	public PageInfo<User> find() {
		//获取第1页，10条内容，默认查询总数count
		PageHelper.startPage(0, 10);
		//紧跟着的第一个select方法会被分页
		List<User> list=uDao.find();
		//用PageInfo对结果进行包装
		PageInfo<User> pageInfo=new PageInfo<User>(list);
		return pageInfo;
	}


	@Override
	public Teacher selectByKey(Integer tId) {
		// TODO Auto-generated method stub
		return tDao.selectByKey(tId);
	}


	@Override
	public List<Teacher> select() {
		// TODO Auto-generated method stub
		return tDao.select();
	}


	@Override
	public List<Menu> findMenuAll() {
		// TODO Auto-generated method stub
		MenuTree menuTree=new MenuTree();
		return menuTree.menuList(mDao.findMenuAll());
	}

	

}
